﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace work01
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            this.textBox1.Text = rnd.Next().ToString();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            label1.Text = "+";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label1.Text = "-";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label1.Text = "*";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            label1.Text = "/";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            label1.Text = "%";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("请输入数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                double value1, value2;
                value1 = Convert.ToDouble(textBox1.Text);
                value2 = Convert.ToDouble(textBox2.Text);
                switch (Convert.ToChar(label1.Text))
                {
                    case '+':
                        label3.Text = (value1 + value2).ToString();
                        break;
                    case '-':
                        label3.Text = (value1 - value2).ToString();
                        break;
                    case '*':
                        label3.Text = (value1 * value2).ToString();
                        break;
                    case '/':
                        //在除法运算中 除数不能为0的情况
                        if (value2 == 0)
                            label3.Text = "输入错误";
                        else
                            label3.Text = (value1 / value2).ToString();
                        break;
                    case '%':
                        //在除法运算中 除数不能为0的情况
                        if (value2 == 0)
                            label3.Text = "输入错误";
                        else
                            label3.Text = (value1 % value2).ToString();
                        break;
                }
            }
        }
        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}